<template>
        <el-card shadow="never" style="max-height: 70vh; overflow: auto">
            <el-form ref="form" :model="form" :rules="rules" label-width="120px" :disabled="disabled">
                <el-form-item label="id:" prop="id" v-show="false">
                    <el-input v-model="form.id" disabled />
                </el-form-item>
                <el-form-item label="直播间:" prop="roomId">
                    <SelectPage v-model="form.roomId" :url="'/admin/live.room/selectPage'" show_field="roomName" show_id="id" query_field="id" :multiple="false" />
                </el-form-item>
                <el-form-item label="赠送用户:" prop="user_id">
                    <SelectPage v-model="form.user_id" :url="'/admin/user/selectPage'" show_field="nickname" show_id="uid" query_field="uid" :multiple="false" />
                </el-form-item>

                <el-form-item label="接收用户:" prop="target_user_id">
                    <SelectPage v-model="form.target_user_id" :url="'/admin/user/selectPage'" show_field="nickname" show_id="uid" query_field="uid" :multiple="false" />
                </el-form-item>
                <el-form-item label="赠送数量:" prop="number">
                    <el-input-number v-model="form.number" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="赠送礼物:" prop="gift_id">
                    <el-input-number v-model="form.gift_id" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="礼物标题:" prop="gift_title" v-if="false">
                    <el-input v-model="form.gift_title" placeholder="请输入礼物标题" clearable />
                </el-form-item>
                <el-form-item label="礼物图片:" prop="gift_image">
                    <ImageUpload v-model="form.gift_image" />
                </el-form-item>
                <el-form-item label="礼物价值:" prop="gift_coin">
                    <el-input-number v-model="form.gift_coin" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="收益价值:" prop="income_money">
                    <el-input-number v-model="form.income_money" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item label="收益比例（%）:" prop="income_rate">
                    <el-input-number v-model="form.income_rate" :step="1" :min="0"></el-input-number>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">确认 </el-button>
                    <el-button type="warning" @click="cancel">取消 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
</template>

<script>
import { regionData } from 'element-china-area-data'
export default {
    name: 'EditForm',
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        editFormParams: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            // 编辑表单验证规则
            rules: {

            },
            form: {  },
            // 区域选择配置
            areaOptions: regionData,

        }
    },
    watch: {
        findFormData: {
           handler(nval) {
                if (JSON.stringify(nval) != '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                    })
                }
            },
            immediate: true,
            deep: false,
        },
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },

        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', this.form)
                }
            })
        },

        // 表单重置
        reset() {
            this.resetForm('form')
        }
    }
}
</script>
